package exception

import "fmt"

func NewApiException(code int, message string) *ApiException {
	return &ApiException{
		Code:    code,
		Message: message,
	}
}

type ApiException struct {
	Code     int    `json:"code"`
	Message  string `json:"message"`
	HttpCode int    `json:"-"`
}

func (ae *ApiException) Error() string {
	return ae.Message
}

var (
	ErrorEmpty    = NewApiException(10001, "字段不能为空")
	ErrorFailed   = NewApiException(10002, "操作失败")
	ErrorNotFound = NewApiException(10003, "未找到该记录")
)

func ErrServerInternal(format string, a ...any) *ApiException {
	return &ApiException{
		Code:    50000,
		Message: fmt.Sprintf(format, a...),
	}
}
